package cn.stronglink.assetmanage.business.task.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.entity.Check;
import cn.stronglink.assetmanage.entity.Task;
import cn.stronglink.assetmanage.index.view.onRecyclerListener;

/**
 * 表单列表
 * @author zww
 *         2018 2018/6/10 18:13
 */
public class TaskListAdapter extends RecyclerView.Adapter<TaskListAdapter.ViewHolder> implements View.OnClickListener{
    private Context mContext;
    private List<Task> datas;
    private onRecyclerListener listener;

    public TaskListAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public TaskListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view =   LayoutInflater.from(mContext).inflate(R.layout.item_task_list,parent,false);
        view.setOnClickListener(this);
        return new TaskListAdapter.ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(TaskListAdapter.ViewHolder holder, int position) {
        Task task = datas.get(position);
        holder.bindRepo(task, position);
        holder.itemView.setTag(position);
    }

    @Override
    public int getItemCount() {

        return datas == null ? 0 : datas.size();
    }

    public void setOnItemClickListener(onRecyclerListener listener) {
        this.listener = listener;
    }

    public void notifyDatasChanged(List<Task> data) {
        this.datas = data;
        notifyDataSetChanged();
    }

    @Override
    public void onClick(View v) {
        if(listener!=null){
            listener.onItemClicked(v, (int) v.getTag());
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder{

        private TextView tv_order_name;
        private TextView tv_status;

        public ViewHolder(View itemView) {
            super(itemView);
            tv_order_name = itemView.findViewById(R.id.tv_check_order_name);
            tv_status = itemView.findViewById(R.id.tv_status);
        }

        public void bindRepo(Task repo, int position) {
            tv_order_name.setText(repo.getId_());
            tv_status.setText(repo.getStatusName());
        }
    }

}
